﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Castle.MicroKernel;
using Castle.Windsor;

//--------------------------------------------
// StackOverflow
// http://stackoverflow.com/questions/4140860/castle-windsor-dependency-resolver-for-mvc-3-rc
//--------------------------------------------

namespace ilanver.Web.IoC
{
    public class WindsorDependencyResolver : IDependencyResolver
    {
        private readonly IWindsorContainer container;

        public WindsorDependencyResolver(IWindsorContainer container)
        {
            this.container = container;
        }

        public object GetService(Type serviceType)
        {
            return container.Kernel.HasComponent(serviceType) ? container.Resolve(serviceType) : null;
        }

        public IEnumerable<object> GetServices(Type serviceType)
        {
            return container.Kernel.HasComponent(serviceType) ? container.ResolveAll(serviceType).Cast<object>() : new object[] { };
        }

        public void AddSubResolver(ISubDependencyResolver subResolver)
        {
            throw new NotImplementedException();
        }

        public void Initialize(IKernel kernel, DependencyDelegate resolving)
        {
            throw new NotImplementedException();
        }

        public void RemoveSubResolver(ISubDependencyResolver subResolver)
        {
            throw new NotImplementedException();
        }

        public bool CanResolve(Castle.MicroKernel.Context.CreationContext context, ISubDependencyResolver contextHandlerResolver, Castle.Core.ComponentModel model, Castle.Core.DependencyModel dependency)
        {
            throw new NotImplementedException();
        }

        public object Resolve(Castle.MicroKernel.Context.CreationContext context, ISubDependencyResolver contextHandlerResolver, Castle.Core.ComponentModel model, Castle.Core.DependencyModel dependency)
        {
            throw new NotImplementedException();
        }
    }
}
